package com.csy.orm_mybatis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csy.orm_mybatis.entity.User;
import com.csy.orm_mybatis.mapper.UserMapper;
import com.csy.orm_mybatis.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author csy
 * @since 2022-04-18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void findByPage() {
        QueryWrapper<User> wrapper = new QueryWrapper();
        Page<User> page = new Page<>(1,1000);
        IPage<User> mapIPage = baseMapper.selectMyPage(page, wrapper);

        System.out.println("总页数"+mapIPage.getPages());
        System.out.println("总记录数"+mapIPage.getTotal());
        List<User> records = mapIPage.getRecords();
        records.forEach(System.out::println);
    }

    @Override
    public User findUserAndTwitter(Long id) {
        return userMapper.findById(id);
    }

    @Override
    public void saveAll(List<User> users) {
        userMapper.saveAll(users);
    }
}
